package com.cardbaobao.cardbabyclient.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.ViewGroup;

/**
 * Description: ScaleUtils
 * Author: Heaven
 * Update: Heaven(2016-05-20 10:38)
 */
public class ScaleUtils {
    /**
     * 获取广告图片比例
     *
     * @return
     */
    public static ViewGroup.LayoutParams getBanner(Activity activity, ViewGroup.LayoutParams lp) {
        int width = 3;
        int height = 2;
        Point point = getPoint(activity);
        double mWidth = point.x;
        double mHeight = (mWidth * height * 1.0) / width;
        lp.height = (int) mHeight;
        lp.width = (int) mWidth;
        return lp;
    }
    /**
     * 获取首页图片比例
     *
     * @return
     */
    public static ViewGroup.LayoutParams getIndexPic(Activity activity, ViewGroup.LayoutParams lp) {
        int width = 349;
        int height = 110;
        Point point = getPoint(activity);
        double mWidth = point.x;
        double mHeight = (mWidth * height * 1.0) / width;
        lp.height = (int) mHeight;
        lp.width = (int) mWidth;
        return lp;
    }

    public static Point getPoint(Activity activity) {
        Point point = new Point();
        try {
            if (Build.VERSION.SDK_INT < 10) {
                DisplayMetrics metric = new DisplayMetrics();
                activity.getWindowManager().getDefaultDisplay().getMetrics(metric);
                point.x = metric.widthPixels;
                point.y = metric.heightPixels;
            } else {
                activity.getWindowManager().getDefaultDisplay().getSize(point);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return point;
    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }





}
